package com.example.demo.base;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.FieldStrategy;
import com.baomidou.mybatisplus.enums.IdType;

import java.util.Date;

/**
 * 实体基础类
 */
@SuppressWarnings({ "serial", "rawtypes" })
public abstract class BaseEntity<T extends Model> extends Model<T> {
    /**
     * 统一配置的主键，采用统一序列赋值
     */
    @TableId(value = "ID", type = IdType.ID_WORKER)
    private Long id;

    /**
     * 创建时间，insert时自动插入数据
     */
    @TableField(value = "CREATE_DATE", strategy = FieldStrategy.NOT_EMPTY, fill = FieldFill.INSERT)
    private Date createDate;

    /**
     * 修改时间，UPDATE时自动插入数据
     */
    @TableField(value = "MOD_DATE", fill = FieldFill.INSERT_UPDATE)
    private Date modDate;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getModDate() {
        return modDate;
    }

    public void setModDate(Date modDate) {
        this.modDate = modDate;
    }

    @Override
    protected Long pkVal() {
        return this.id;
    }
}
